package cn.wolfcode.wolf.user.controller;

import cn.wolfcode.wolf.user.domain.UserInfo;
import cn.wolfcode.wolf.user.service.UserInfoService;
import cn.wolfcode.wolf.core.utils.Result;
import cn.wolfcode.wolf.user.vo.RegisterRequest;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserInfoController {

    private final UserInfoService userinfoService;

    public UserInfoController(UserInfoService userinfoService) {
        this.userinfoService = userinfoService;
    }


    @RequestMapping(value = "/login",params = {"phone","password"},name = "登陆验证",method = RequestMethod.POST)
    public Result<Map<String,Object>> login(String phone, String password){
       Map<String,Object> map = userinfoService.login(phone,password);
       return Result.success(map);
    }
    @GetMapping("/phone/exists")
    public Result<Boolean> checkPhoneExists(String phone){
        return Result.success(userinfoService.findByPhone(phone)!=null);
    }
    @PostMapping("/register")
    public Result<?> register(RegisterRequest registerRequest){
        userinfoService.register(registerRequest);
        return Result.success("发送成功");
    }


    @GetMapping
    public Object list(){
        return userinfoService.list();
    }
}
